/**
 * Created by zhushoude on 2017/5/18.
 */
var i = 1;
var totalPage = "";
$(function(){
    var token=localStorage.getItem("token");
    gridObj = $.fn.bsgrid.init('g_tabYeh', {
        ajaxType : 'post',
        url :  server_url+'/rest/demand/demandList.do?ran=' + Math.random() + '&token=' + token,
        autoLoad : true,
        pageSizeSelect : true,
        stripeRows : true,
        pageSize : 10,
        displayBlankRows : false,
        isProcessLockScreen : true,
        rowSelectedColor : false,
        showPageToolbar:true,
        rowHoverColor:true
    });

});
function operate(record, rowIndex, colIndex, options) {

    return  '<a href="javascript:demandSupply(\'' + gridObj.getRecordIndexValue(record.details[0], 'demandId') + '\');">报价('+record.priceNum+')</a>'+
             '<a href="javascript:modifyDemand(\'' + gridObj.getRecordIndexValue(record.details[0], 'demandId') + '\');">修改</a>'+
             '<a href="javascript:delDemand(\'' + gridObj.getRecordIndexValue(record.details[0], 'demandId') + '\');">删除</a>';

};

// 数据表格参数查询
function doSearch() {
    var searchParames = $('#myform').serialize();
    gridObj.search(searchParames);
}

function modifyDemand(id) {
    var url='demand/modifyDemand.do?id='+id;
    tl_config.loadToWorkArea(url);
}
function delDemand(id) {
    if(empty(id)){
        easyDialog.open({
            container : {
                header : '温馨提示',
                content : '请选择要操作的记录！'
            },
            autoClose : 2000
        });
        return;
    }
    easyDialog.open({
        container : {
            header : '删除确认',
            content : '您确定要删除需求单么？',
            yesFn : function(){
                $.ajax({
                    url:server_url+'/rest/demand/delDemand.do?ran='+Math.random()+"&token="+token,
                    type:'get',
                    data:{demandId:id},
                    success:function(data){
                        if(data.retCode=="0000"){
                            doSearch();
                        }
                        else{
                            easyDialog.open({
                                container : {
                                    header : '提示',
                                    content : data.retMsg
                                },
                                autoClose : 2000
                            });
                        }
                    }
                })
            },
            noFn : true
        }
    });
}

//报价
function demandSupply(id) {
    var url='demand/demandSupplyList.do?id='+id;
    tl_config.last_url=url;
    tl_config.loadToWorkArea(url);
}
function buyerName(record, rowIndex, colIndex, options){
    if( record.buyer != null &&  record.buyer != ''&& record.buyer!= undefined){
        return record.buyer.buyerName;
    }else{
        return "";
    }
};
function deliveryAreaName(record, rowIndex, colIndex, options){
    if(  record.details[0].deliveryArea != null &&  record.details[0].deliveryArea != ''&&  record.details[0].deliveryArea != undefined){
        return record.details[0].deliveryArea;
    }else{
        return "";
    }
};
function cateName(record, rowIndex, colIndex, options){
    return record.details[0].cateName;
};
function categoryName(record, rowIndex, colIndex, options){
    return record.details[0].categoryName;
};

function productName(record, rowIndex, colIndex, options){
    return record.details[0].productName;
};
function amount(record, rowIndex, colIndex, options){
    return record.details[0].amount;

};

function price(record, rowIndex, colIndex, options){
    var minPrice = record.details[0].minPrice;
    var maxPrice=record.details[0].maxPrice;
    if(minPrice != null || maxPrice != ''){
        return minPrice+'-'+maxPrice;
    }else{
        return "";
    }
};
function isOnLine(record, rowIndex, colIndex, options){
    if(record.isOnLine != null && record.isOnLine != ''){
        if(record.isOnLine==1)
        return "上架";
        else
            return "下架";
    }else{
        return "";
    }
};


